/*
ID:luongho3
LANG:JAVA
TASK:snail
 */
import java.io.File;
import java.io.PrintStream;
import java.util.Scanner;

public class snail {

	int B, N;
	int[][] m;
	int max = 1;

	public static void main(String[] args) throws Exception {
		snail prob = new snail();
		prob.read();
		prob.solve();
	}
	
	public void read() throws Exception {
		Scanner scanner = new Scanner(new File("snail.in"));
		N = scanner.nextInt();
		B = scanner.nextInt();
		m = new int[N+1][N+1];
		m[1][1] = 2;
		for (int i=1;i<=B;++i) {
			String str = scanner.next();
			char c = str.charAt(0);
			int r = Integer.parseInt(str.substring(1));
			m[r][c-'A'+1] = 1;
		}
	}
	
	public void solve() throws Exception {
		PrintStream ps = new PrintStream(new File("snail.out"));
		System.setOut(ps);
		dfs(1,1,1,0,1);
		dfs(1,1,0,1,1);
		System.out.println(max);
		ps.close();
	}
	
	private void dfs(int x, int y, int dx, int dy, int count) {
//		print();
		int sx, sy;
		sx = x;
		sy = y;
		boolean recrossed = false;
		do {
			if (sx+dx<= N && sy+dy<= N && sx+dx>=1 && sy+dy>=1) {
				sx += dx;
				sy += dy;
				if (m[sy][sx] == 0) {
					m[sy][sx] = 2;
					count++;
				}
				else {
					if (m[sy][sx] == 2) {
						recrossed = true;
//						System.out.println(sy + " " + sx + " " + count);
					}
					sx -= dx;
					sy -= dy;
					break;
				}
			}
			else {
				break;
			}
		} while(true);
		if (!recrossed) {
			if (sx != x || sy !=y) {
				// not recrossed, then continue dfs
				if (dx == 0) {
					dfs(sx,sy,1,0,count);
					dfs(sx,sy,-1,0,count);	
				}
				else if (dy == 0) {
					dfs(sx,sy,0,1,count);
					dfs(sx,sy,0,-1,count);
				}
			}
		}
		// unmark
		while (sx != x || sy != y) {
			m[sy][sx] = 0;
			sx -= dx;
			sy -= dy;
		}
		if (count > max) {
			max = count;
		}
	}
	
	void print() {
		for (int i=1;i<=N;++i) {
			for (int j=1;j<=N;++j) {
				System.out.print(m[i][j]);
			}
			System.out.println();
		}
		System.out.println();
	}

}
